#!/usr/bin/env python
#coding: utf-8
'''
Created on 2017年6月12日

@author: Administrator
'''
from attachment import settings
from celery import task
from common.decorators.celery import task_exception_handler
from common.utils import es
from elasticsearch.exceptions import TransportError
import logging

# 为loggers中定义的名称
logger = logging.getLogger("celery")

@task
@task_exception_handler
def update_oss_file_to_es_task(action):
    #定义es
    try:
        es.es_client.index(settings.ES_INDEX_ATTACHMENT_LIST, doc_type=settings.ES_INDEX_ATTACHMENT_LIST_TYPE, body=action, id=action["id"])
        logger.info(u"update oss file to es by id %s success;" % action["id"]) 
    except TransportError:
        logger.warning(u"update oss file to es by id %s faild;" % action["id"]) 
        
